package cn.com.netedge.iot.frontend.datasave.mq;

import cn.com.netedge.iot.common.constants.CacheKeyConstants;
import cn.com.netedge.iot.common.constants.Globals;
import cn.com.netedge.iot.common.mq.MqMessageListener;
import cn.com.netedge.iot.common.utils.RedisUtil;
import cn.com.netedge.iot.frontend.datasave.config.DataSaveConfig;
import cn.com.netedge.iot.frontend.datasave.utils.MqConsumeUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

@Component
@Scope( "prototype" )
public class DataCDailyMessageConsumer extends MqMessageListener {
    private static final Logger logger = LoggerFactory.getLogger(DataCDailyMessageConsumer.class);
    @Override
    public void execute(String msg) {
        MqConsumeUtil.consumeFreezeDataMessage(queueName, msg,CacheKeyConstants.KEY_DATA_C_DAILY);
    }

    @Override
    public boolean checkCacheQueue() {
        long len = RedisUtil.llen(CacheKeyConstants.KEY_DATA_C_DAILY + DataSaveConfig.getMachineName());
        if (len > Globals.MAX_CACHE_SIZE) {
            return false;
        }
        return true;
    }
}
